/*
 * Copyright (C) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "avcodec_log.h"
#ifndef CLIENT_SUPPORT_CODEC
#include "fcodec_loader.h"
#include "hevc_decoder_loader.h"
#ifdef SUPPORT_CODEC_VP8
#include "vp8_decoder_loader.h"
#endif
#ifdef SUPPORT_CODEC_VP9
#include "vp9_decoder_loader.h"
#endif
#ifdef SUPPORT_CODEC_AV1
#include "av1_decoder_loader.h"
#endif
#include "avc_encoder_loader.h"
#endif
#include "avcodec_errors.h"
#include "audio_codeclist_info.h"
#include "codeclist_builder.h"

namespace {
[[maybe_unused]] constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FRAMEWORK, "CodecList_builder"};
}
namespace OHOS {
namespace MediaAVCodec {
#ifndef CLIENT_SUPPORT_CODEC
int32_t VideoCodecList::GetCapabilityList(std::vector<CapabilityData> &caps)
{
    auto ret = FCodecLoader::GetCapabilityList(caps);
    if (ret == AVCS_ERR_OK) {
        AVCODEC_LOGI("Get capability from fcodec successful");
    }
    return ret;
}

int32_t VideoHevcDecoderList::GetCapabilityList(std::vector<CapabilityData> &caps)
{
    auto ret = HevcDecoderLoader::GetCapabilityList(caps);
    if (ret == AVCS_ERR_OK) {
        AVCODEC_LOGI("Get capability from hevc decoder successful");
    }
    return ret;
}

#ifdef SUPPORT_CODEC_VP8
int32_t VideoVp8DecoderList::GetCapabilityList(std::vector<CapabilityData> &caps)
{
    auto ret = Vp8DecoderLoader::GetCapabilityList(caps);
    if (ret == AVCS_ERR_OK) {
        AVCODEC_LOGI("Get capability from vp8 decoder successful");
    }
    return ret;
}
#endif

#ifdef SUPPORT_CODEC_VP9
int32_t VideoVp9DecoderList::GetCapabilityList(std::vector<CapabilityData> &caps)
{
    auto ret = Vp9DecoderLoader::GetCapabilityList(caps);
    if (ret == AVCS_ERR_OK) {
        AVCODEC_LOGI("Get capability from vp9 decoder successful");
    }
    return ret;
}
#endif

#ifdef SUPPORT_CODEC_AV1
int32_t VideoAv1DecoderList::GetCapabilityList(std::vector<CapabilityData> &caps)
{
    auto ret = Av1DecoderLoader::GetCapabilityList(caps);
    if (ret == AVCS_ERR_OK) {
        AVCODEC_LOGI("Get capability from av1 decoder successful");
    }
    return ret;
}
#endif

int32_t VideoAvcEncoderList::GetCapabilityList(std::vector<CapabilityData> &caps)
{
    auto ret = AvcEncoderLoader::GetCapabilityList(caps);
    if (ret == AVCS_ERR_OK) {
        AVCODEC_LOGI("Get capability from avc encoder successful");
    }
    return ret;
}
#endif
int32_t AudioCodecList::GetCapabilityList(std::vector<CapabilityData> &caps)
{
    auto audioCapabilities = AudioCodeclistInfo::GetInstance().GetAudioCapabilities();
    for (const auto &v : audioCapabilities) {
        caps.emplace_back(v);
    }
    return AVCS_ERR_OK;
}
} // namespace MediaAVCodec
} // namespace OHOS